#include "game-thread.hh"

#include "server.hh"

GameThread::GameThread (Server* s,
			const tbb::concurrent_hash_map<int, boost::shared_ptr<Client> >& cl,
			ObjVect* objvect):
  r_ (),
  cl_ (cl),
  objvect_ (objvect),
  rh_ (s, objvect)
{
}

GameThread::~GameThread ()
{
  std::cout << "game thread deleted" << std::endl;
}

void
GameThread::push (const boost::shared_ptr<Request>& r)
{
  r_.push (r);
}
 
void
GameThread::send_physic_updates (const std::set<Object*>& mov_obj)
{
  tbb::concurrent_hash_map<int, boost::shared_ptr<Client> >::const_iterator it;

  for (std::set<Object*>::const_iterator jt = mov_obj.begin ();
       jt != mov_obj.end (); ++jt)
  {
    for (it = cl_.begin (); it != cl_.end (); ++it)
    {
      it->second->nm ()->send (RType::UPDATE_OBJ, (*jt)->tonetupdate ());
      // it->second->nm ()->send (RType::UPDATE_OBJ, (*jt)->tonet ());
    }
  }
}

